<template>
	<view class="home-wrap u-m-b-20">
		<base-nav-bar :isBack="true" :background="{'background':'#fff'}">
			<text
				slot="content"
				style="color: #333; width: 100%; text-align: center;padding-left: 20rpx;"
			>
				用户消费明细
			</text>
		</base-nav-bar>
		<view class="course-add u-flex u-flex-column u-flex-items-center u-flex-between" :style="{'top':customBar+ 'px' }">
			<view class="u-flex course-add-btn u-flex-start u-flex-items-center" :style="{'background': 'url('+HTTP_IMG_URL()+'/merchant/points/info_log.png) no-repeat center 100%','background-size': '100%'}">
				<image class="course-add-icon" :src="userInfo.userLogo" ></image>
				<view class="u-flex u-flex-column u-flex-between u-m-l-40">
					<view class="course-add-txt u-m-b-10">{{ userInfo.userName?userInfo.userName:''}}</view>
					<view class="course-add-txt-min">消费{{ userInfo.count?userInfo.count:'' }}次，剩余{{ userInfo.score?userInfo.score:'0' }}固定积分</view>
				</view>
			</view>
			<view class="u-flex u-flex-between u-flex-items-center points-title">
				<view class="u-flex">
					<view class="integral-icon u-flex u-flex-start u-flex-items-center u-m-r-20">
						<view class="left-point u-m-r-14"></view>
						<view class="right-point"></view>
					</view>
					<view class="integral-title">预存信息</view>
				</view>
				<view class="integral-history u-flex u-flex-between u-flex-items-center" @click="jump('/pages-merchant/points/rechargeRecord?id='+userId)">
					<view class="integral-history-txt">
						充值记录
					</view>
					<u-icon name="arrow-right" size="14" :color="'#b9b8b8'"></u-icon>
				</view>
			</view>
		</view>		<!-- 课程预约记录 -->
		<view class="content-box"  v-if="!isEmpty" style="margin-top: 280rpx;">
			<view class="u-flex u-flex-column u-flex-between merchant-box u-p-t-20 u-m-l-30 u-m-r-30 u-m-b-20" v-for="(item,index) in courseList" :key="index"
			      @click="jump('/pages-merchant/points/integralDetails?id='+item.order_id)">
				<view class="course-item u-flex u-flex-between u-flex-items-start u-p-l-20 u-p-b-20 u-p-r-20">
					<view class="u-flex u-flex-start u-flex-items-center u-flex-3">
						<image :src="item.image" class="merchant-logo"></image>
						<view class="u-flex u-flex-items-start u-flex-column u-flex-between u-m-l-20" style="height: 80rpx;">
							<view class="course-item-text">{{ item.nbame }}</view>
							<view class="course-item-number u-m-t-10">消费时间:{{item.createtime}}</view>
						</view>
					</view>
					<view class="course-item-btn-group u-flex u-flex-1 u-flex-column u-flex-around">
						<view class="course-item-btn">{{ item.score }}</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 数据为空 -->
		<u-empty
			v-if="isEmpty"
			mode="data"
			:marginTop="220"
			text="暂无课程记录"
		>
		</u-empty>
		<!-- 更多 -->
		<u-loadmore v-if="!isEmpty" height="80rpx" :status="loadStatus" icon-type="flower" color="#ccc"/>
	</view>
</template>

<script>
let systemInfo = uni.getSystemInfoSync();
let menuButtonInfo = {};
// #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO || MP-QQ
menuButtonInfo = uni.getMenuButtonBoundingClientRect();
// #endif
import { mapGetters } from 'vuex';
import { HTTP_IMG_URL } from '../../config/app.js'
import BaseNavBar from "../../components/BaseNavBar.vue";
export default {
	components: {
		BaseNavBar
	},
	data() {
		return {
			userInfo:{},
			courseList:[
			],
			loadStatus   : 'nomore', //loadmore-加载前的状态，loading-加载中的状态，nomore-没有更多的状态
			currentPage  : 1,
			lastPage     : 1,
			total  : '',
			isEmpty      : false,
			userId: '',
		};
	},
	computed: {
		...mapGetters(['isLogin', 'userInfo']),
		customBar() {
			let statusBarHeight = systemInfo.statusBarHeight;
			console.log("====statusBarHeight",statusBarHeight)
			// #ifndef MP
			return systemInfo.platform == 'android' ? statusBarHeight + 50 : statusBarHeight + 45;
			// #endif
			// #ifdef MP-WEIXIN
			return menuButtonInfo.bottom + menuButtonInfo.top - statusBarHeight;
			// #endif
			// #ifdef MP-ALIPAY
			return statusBarHeight + systemInfo.titleBarHeight;
			// #endif
		}
	},
	onPullDownRefresh() {
	
	},
	
	onShow() {
		if(!this.isLogin){
		
		}
		
	},
	onHide() {
	},
	onLoad(options) {
		if(options&&options.id){
			this.userId = options.id
			this.courseList = [];
			this.currentPage = 1;
			this.getMourserList()
		}else{
			this.courseList = [];
			this.currentPage = 1;
		}
		
	},
	created() {
		// 触底监听
		uni.$on('uOnReachBottom', data => {
			if (this.loadStatus == 'loadmore') {
				this.currentPage += 1;
				this.getMourserList();
			}
		});
	},
	methods: {
		HTTP_IMG_URL() {
			return HTTP_IMG_URL
		},
		// 路由跳转
		jump(path, parmas) {
			uni.navigateTo({
				url: path,
				query: parmas
			});
		},
		// 消费列表
		getMourserList() {
			let that = this;
			that.$Api.merchant.scoreFixedLogEdit({
				page    : that.currentPage,
				pageSize: 20,
				user_id:that.userId
			}).then(res => {
				that.userInfo = {
					userName: res.data.nickname,
					userLogo: res.data.avatar,
					count: res.data.xh_count,
					score: res.data.sy_score
				}
				that.courseList = [...that.courseList, ...res.data.list.data];
				that.isEmpty    = !that.courseList.length;
				that.loadStatus = that.currentPage < res.data.list.last_page ? 'loadmore' : 'nomore';
			});
		},
	}
};
</script>

<style lang="scss" scoped>
/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
.home-wrap {
	min-height: 100vh;
	background: #F6F6F8;
}
.kehu-item {
	border-radius: 20rpx;
	width: 100%;
	.swipers{
		width: 100%;
	}
}
.nickname{
	font-size: 34rpx;
	font-weight: bold;
}
.course-add{
	position: fixed;
	background: #F6F6F8;
	z-index: 1000;
	width: 100%;
	padding: 0rpx 0;
	height: 280rpx;
	.course-add-btn{
		width: 100% ;
		min-height: 180rpx;
		padding: 0 30rpx;
		.course-add-icon{
			width: 120rpx;
			height: 120rpx;
			border-radius: 50%;
		}
		.course-add-txt{
			color: #fff;
			font-size: 34rpx;
			
		}
		.course-add-txt-min{
			color: #fff;
			font-size: 26rpx;
		}
	}
	.points-title{
		width: calc(100% - 60rpx);
		height: 80rpx;
		padding: 0 10rpx 30rpx;
	}
}

.content-box{
	.merchant-box{
		background:linear-gradient( 180deg, #E8FFED 0%,#FFFFFF 30%, #FFFFFF 100%);
		box-shadow: 0px 0px 6px 0px rgba(0,0,0,0.1), inset 0px 1px 0px 0px #FFFFFF;
		border-radius: 30rpx;
		position: relative;
		.course-item{
			width: 100%;
			margin: 0rpx 0rpx 20rpx;
			.merchant-logo{
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
			}
			.merchant-icon{
				width: 30rpx;
				height: 30rpx;
			}
			.course-item-text{
				font-weight: 400;
				font-size: 32rpx;
				color: #000000;
			}
			.course-item-number{
				font-weight: 400;
				font-size: 26rpx;
				color: #9A9A9A;
			}
			.course-item-btn-group{
				.course-item-btn{
					text-align: right;
					font-weight: 500;
					font-size: 38rpx;
					color: #333;
				}
			}
		}
		
	}
}
.integral-icon{
	.left-point{
		width: 5px;
		height: 20px;
		background: #B9DEC5;
		border-radius: 4px;
	}
	.right-point{
		width: 5px;
		height: 13px;
		background: #30AA4D;
		border-radius: 4px;
	}
}
</style>
